<template>
    <div class="fl">
        <main>
            <div class="cent">结算</div>
            <img src="../../public/image/testimonial-bg.jpg" alt="玫瑰" width="100%" height="290px" class="lbt" />
        </main>
        <div class="container">
            <div class="js__top">
                <div class="top__mentum">
                    <h3>点击切换地址</h3>
                </div>
                <div class="top__mentum">
                    <h3>点击输入你的优惠劵</h3>
                </div>
            </div>
            <div class="box">
                <div class="box__address">
                    <h3>地址管理</h3>
                    <label for="">
                        <p>名字 <span class="address__span--red">*</span></p>
                        <input type="text">
                    </label>
                    <label for="">
                        <p>电话 <span class="address__span--red">*</span></p>
                        <input type="text">
                    </label>
                    <label for="">
                        <p>所在地区 <span class="address__span--red">*</span></p>
                        <input type="text">
                    </label>
                    <label for="">
                        <p>详细地址 <span class="address__span--red">*</span></p>
                        <input type="text">
                    </label>
                </div>
                <div class="box__payment">
                    <div class="payment__main">
                        <h3>您的订单</h3>
                        <ul>
                            <li>
                                <p>产品</p>
                                <p>总价</p>
                            </li>
                            <li v-for="(item,index) in cart" :key="index">
                                <p>{{item.name}}</p>
                                <p>{{"￥"+ item.price}}</p>
                            </li>
                            <li>
                                <p>运输</p>
                                <p>免费送货</p>
                            </li>
                            <li>
                                <p>合计订单</p>
                                <p class="main__total">￥{{total}}</p>
                            </li>
                        </ul>
                        <p>备注</p>
                        <textarea class="mian__textarea" name="beiz" id="" cols="30" rows="3"
                            placeholder="选填，请先和商家达成一致"></textarea>
                        <button class="mian__button-js" @click="clear">
                            结算
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style lang="less" scoped>
    body {
        line-height: 1.75;
    }

    textarea {
        outline: none;
    }

    button,
    input {
        border: none;
        outline: none;
        background: none;
    }

    main {
        position: relative;

        .cent {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #222222;
            font-size: 42px;
            font-family: "Lora", serif;
            z-index: 30;
        }
    }

    .container {
        width: 1200px;
        height: 800px;
        padding: 0 15px;

        .js__top {
            font-size: 14px;
            padding: 0 15px;
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;

            .top__mentum {
                width: 50%;
                height: 72px;
                padding: 0 15px;
                color: #848B8a;
                cursor: pointer;

                h3 {
                    background-color: #f6f6f6;
                    border-top: 3px solid #bc8246;
                    font-size: 14px;
                    font-weight: 400;
                    position: relative;
                    margin-bottom: 25px;
                    padding: 14px 28px 14px 49px;
                }
            }


        }

        .box {
            height: 600px;
            display: flex;

            .box__address {
                width: 50%;
                padding: 0 12px;

                h3 {
                    height: 47px;
                    margin-bottom: 20px;
                    padding-bottom: 10px;
                    font: 30px;
                    color: #201f1f;
                    padding: 0 15px;
                }

                label {
                    width: 100%;
                    padding: 0 15px;

                    .address__span--red {
                        color: red;
                    }

                    input {
                        border: 1px solid #eaedff;
                        height: 45px;
                        padding-left: 10px;
                        width: 100%;
                        color: #6f7172;
                    }
                }
            }

            .box__payment {
                width: 50%;
                padding: 0 24px 0 12px;

                .payment__main {
                    width: 100%;
                    padding: 30px 40px 45px;
                    border: 3px solid #eaedff;

                    h3 {
                        height: 47px;
                        margin-bottom: 20px;
                        padding-bottom: 10px;
                        font: 30px;
                        color: #201f1f;
                        border-bottom: 1px solid #eaedff;
                    }

                    ul {
                        li {
                            border-bottom: 1px solid #eaedff;
                            border-right: medium none;
                            color: #6f7172;
                            font-size: 14px;
                            display: flex;

                            p {
                                width: 50%;
                                text-align: left;
                                padding: 15px 0;
                                margin: 0;
                            }

                            .main__total {
                                font-size: 20px;
                                font-weight: 500;
                                color: #f34f3f;
                            }
                        }
                    }

                    .mian__textarea {
                        width: 100%;
                        padding: 0 15px;
                        border: 1px solid #eaedff;
                    }

                    .mian__button-js {
                        height: 50px;
                        line-height: 50px;
                        width: 100%;
                        padding: 0 15px;
                        text-align: center;
                        color: white;
                        background-color: #f34f3f;
                    }
                }
            }
        }
    }
</style>
<script>
    export default {
        data() {
            return {
                cart: [],
                total: null
            }
        },

        methods: {
            clear() { 
                var a = confirm("是否购买")
                if (a) {
                    this.$router.push('/shop')
                }
                this.$store.commit('removeAll')
            }

        },

        mounted() {
            var user = localStorage.getItem("user");
            if (localStorage.getItem(user) !== null) {
                // console.log(JSON.parse(localStorage.getItem(user)));
                this.cart = JSON.parse(localStorage.getItem(user));
                this.$store.state.car = this.cart;
            }

            for (const item of this.cart) {
                this.total += Number(item.price)
            }
        }
    }
</script>